package com.tanhua.server.controller;

import com.tanhua.model.domain.Settings;
import com.tanhua.model.dto.QuestionDto;
import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.SettingsVo;
import com.tanhua.server.service.BlackService;
import com.tanhua.server.service.QuestionService;
import com.tanhua.server.service.SettingsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/users")
public class SettingsController {

    @Autowired
    private SettingsService settingsService;

    @Autowired
    private QuestionService questionService;

    @Autowired
    private BlackService blackService;

    /**
     * 查询通用设置
     *
     * @return
     */
    @GetMapping("/settings")
    public ResponseEntity settings() {
        //调用service查询
        SettingsVo vo = settingsService.settings();
        return ResponseEntity.ok(vo);
    }

    /**
     * 设置陌生人问题
     */
    @PostMapping("/questions")
    public ResponseEntity questions(@RequestBody QuestionDto questionDto) {
        //获取参数
        String content = questionDto.getContent();
        //调用方法设置
        questionService.addQuestion(content);
        return ResponseEntity.ok(null);
    }


    /**
     * 通知设置-保存
     */
    @PostMapping("/notifications/setting")
    public ResponseEntity notifications(@RequestBody Settings settings) {
        settingsService.notificationsSettings(settings);
        return ResponseEntity.ok(null);
    }


    /**
     * 查询黑名单用户
     */
    @GetMapping("/blacklist")
    public ResponseEntity blackList(
            @RequestParam(defaultValue = "1") int page,
            @RequestParam(defaultValue = "10") int pageSize) {
        //调用api查询
        PageResult pageResult = blackService.findPage(page, pageSize);
        return ResponseEntity.ok(pageResult);
    }


    /**
     *将单个好友移出黑名单
     */
    @DeleteMapping("/blacklist/{uid}")
    public ResponseEntity deleteBlack(@PathVariable("uid") Long blackId){
        //调用Service移出黑名单
        blackService.deleteBlackUser(blackId);
        return ResponseEntity.ok(null);
    }
}
